package orm

import (
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"log"
	"os"
	"wx_build/global"
)

func Init() {
	//初始化配置文件
	newlogger := logger.New(
		log.New(os.Stdout, "\r\n", log.LstdFlags),
		logger.Config{})
	//连接数据库
	db, err := gorm.Open(sqlite.Open("./local.db?cache=shared&mode=rwc&_journal_mode=WAL"), &gorm.Config{Logger: newlogger})
	if err != nil {
		panic(err)
	}
	//设置连接池
	sqlDb, _ := db.DB()
	sqlDb.SetMaxIdleConns(200) //设置最大连接数
	sqlDb.SetMaxOpenConns(200)
	global.Sqlite = db
}
